<?php
// +----------------------------------------------------------------------
// | Description: about us
// +----------------------------------------------------------------------
// | Author: orchief
// +----------------------------------------------------------------------
// | Date: 2018-03-06 13:37:11
// +----------------------------------------------------------------------

namespace App\Model;

use App\Common\Model;
use think\Cache;

class SystemConfig extends Model
{
    protected $fuzzyConditions = null;
    protected $clearConditions = null;
    protected $returnFields = '';
    protected $rangeConditions = null;
    protected $union_fuzzyConditions = null;
    protected $foreignConditions = null;
    protected $name = 'system_config';

    /**
     * 获取配置列表
     * @param  array   $param  [description]
     */
    public function getDataOfList()
    {
        $list = $this->select();
        $data = array();
        foreach ($list as $key => $val) {
            $data[$val['name']] = $val['value'];
        }
        return $data;
    }

        /**
     * 批量修改配置
     * @param  array   $param  [description]
     */
    public function createData($param, $field=true)
    {
        $list = [
            ['id' => 1, 'value' => $param['SYSTEM_NAME']],
            ['id' => 2, 'value' => $param['SYSTEM_LOGO']],
            ['id' => 3, 'value' => $param['LOGIN_SESSION_VALID']],
            ['id' => 4, 'value' => $param['IDENTIFYING_CODE']],
            ['id' => 5, 'value' => $param['LOGO_TYPE']],
        ];
        if ($this->saveAll($list)) {
            $data = $this->getDataOfList();
            Cache::set('DB_CONFIG_DATA', $data, $param['LOGIN_SESSION_VALID']);
            return $data;
        }
        $this->error = '更新失败';
        return false;
    }
}
